<header class="header header_1">
    <div class="fix_nav">
        <div class="nav_inner">
            <a class="nav-left back-icon" href="javascript:history.go(-1);">返回</a>
            <div class="tit">购物车</div>
        </div>
    </div>
</header>
<div class="container ">
    <div class="row rowcar">
    <?php if(empty($list)):?>
        <div class="empty">
            <center><img style="margin:10px auto ;" src="/misc/images/cartIcon.png"/></center>
            <center><span class="f14">您的购物车还是空的，赶紧行动吧！</span></center>
            <div class="row">
                <center style="width:40%;margin:0 auto;"><p><button type="button" id="buyBtn1" class="btn btn-primary btn-block mt10" onClick="location.href='/';">返回购物</button></p> </center>
            </div>
        </div>
        <?php else:?>
        <ul class="list-group list-group_12">
            <li class="list-group-item text-primary">
                <div class="icheck pull-left mr5">
                    <input type="checkbox" checked="checked" value="12" class="ids" name="icheck_group" id="buy-sele12" data-price="">
                    <label for="buy-sele12">
                        <span></span>
                    </label>
                </div>
                产品信息
            </li>
            <?php foreach ($list as $item):?>
            <li class="list-group-item hproduct clearfix">

                <div class="p-pic"><a href="/product/detail/goods_id/<?=$item['product_id']?>.html"><img src="<?=$item['product_thumb']?>" class="img-responsive"></a></div>
                <div class="p-info">
                    <a href="/product/detail/goods_id/<?=$item['product_id']?>.html">
                        <p class="p-title"><?=$item['product_name']?></p>
                        <p class="p-origin">
                            <a href="javascript:void(0);" goods_id="(<?=$item['product_id']?>)" class="close p-close">&times;</a>
                            <em class="price">¥<?=price_format($item['price'])?></em>
                        </p>
                    </a>
                </div>
            </li>
            <li class="list-group-item clearfix">
                <div class="pull-left mt5"><span class="gary">小计：</span> <em class="red productTotalPrice">￥<?=price_format($item['price'])?></em></div>
                <div class="btn-group btn-group-sm control-num product_<?=$item['product_id']?>" >
                    <a class="btn btn-default" href="javascript:void(0);"  onclick="DisDe(this,<?=$item['product_id']?>)" ><span class="glyphicon glyphicon-minus gary"></span></a>
                    <input type="tel" value="1" class="btn gary2 Amount">
                    <a class="btn btn-default" href="javascript:void(0);"  onclick="Increase(this,<?=$item['product_id']?>)" ><span class="glyphicon glyphicon-plus gary"></span></a>
                </div>
            </li>
            <?php endforeach;?>
        </ul>
    <?php endif;?>
    </div>
</div>
<div class="fixed-foot">
    <div class="fixed_inner">
        <div class="pay-point">
            <div class="icheck pull-left mr10">
                <input type="checkbox" checked="checked" value="1" id="buy-sele-all">
                <label for="buy-sele-all">
                    <span class="mt10"></span>全选
                </label>
            </div>
            <p>合计：<em class="red f22" >￥<span id="totalPrice"><?=price_format($total)?></span></em></p>
        </div>
        <div class="buy-btn-fix">
            <a href="javascript:void(0);" class="btn btn-danger btn-buy">去结算</a>
        </div>
    </div>
</div>
<script  type="text/javascript">
    var ship_fee =0;
    var order_coupon = 0;
    var use_card = false;
    $(document).ready(function(){
        $(".close").click(function(){
            var $this = $(this);
            var goods_id = $this.attr('goods_id');
            showPageLoadingMsg('处理中...');

            $.getJSON('/cart/drop?goods_id=' + goods_id, function(result){
                $(".ui-loader").remove();
                if(result.status == 1){
                    var li = $this.parents('li');
                    li.next().remove();
                    li.remove();

                    floatNotify.simple('删除商品成功');
                    $('#totalPrice').html(result.amount);
                }else{
                    floatNotify.simple(result.msg);
                }
            });
        });

        $(".ids").click(function(){
            var flag = $(this).attr("checked") === true? true: false;
            if(!flag){
                $("#buy-sele-all").attr("checked", false);
                $("#buy-sele-all").val(0);
            }
        });
        // 全选，全不选
        $("#buy-sele-all").click(function() {
            var flag = $(this).val()  ;

            if(flag ==1){
                $(this).val(0);
                $(".ids").attr("checked", false);
            }else{
                $(this).val(1);
                $(".ids").attr("checked", true);
            }
        });
        $(".btn-buy").click(function(){

            if($("input[class='ids']:checked").length)
            {
                var ids = '';
                $("input[class='ids']:checked").each(function(i){
                    if(ids == ''){
                        ids = $(this).val();
                    }else{
                        ids += '|'+$(this).val();
                    }
                });

                location.href="/cart/settle/sb.html?rec_ids="+ids;
            }
            else{
                alert("请选择要操作的记录!");
            }
        });

        /* 设置购物车商品 */
        cart.init();
        var items = [{"id":"12","name":"RISOU Repair Gel \u6297\u76b1\u4fee\u62a4\u51dd\u9732(32ml+8ml)\u8fdb\u53e3","image_md5 ":null,"price":"1598.00","market_price":"1988.00","qty":1,"special":null,"gift":null,"ship":"1","only_money":"0","limit_num":"0","card_id":null}];

        console.info(items);
        cart.setItems(items);

        $(".ids").bind("click", function(){

            calculate();
        });
        $("#buy-sele-all").bind("click", function(){

            calculate();
        });

        function calculate(){
            var ids = [];
            var tatal = 0;
            $("input[class='ids']:checked").each(function(i){
                ids.push($(this).val());
            });

            var new_items = [];
            for(var i in items){
                for(var j in ids){
                    if(items[i]['id'] == ids[j]){
                        new_items.push(items[i]);
                        break;
                    }
                }
            }
            cart.setItems(new_items);
        }

    });
</script>
